<?php
/**
 * 登录控制
 */
$login_user=!empty($_POST['user_name'])?$fun->checkInput(trim($_POST['user_name'])):"";
$login_password=(isset($_POST['password'])?trim($_POST['password']):"");
$login_pwd=md5($login_password.$pwdconstant);//加密+常量

if(!empty($userInfo['uid'])){
	$fun->msg("您已经登录,正在进入首页...",$list_url['index'],2,$title="登录提示",$back_color="f78a12");
}else if(($login_user== "")||($_POST['password'] == "")){
	$fun->msg("请您认真填写登录信息",$return_page_url,2,$title="登录提示",$back_color="f78a12");
}else{
	
	$justice=$db->get_one("SELECT `uid`, `uname`, `realname`, `ncname`, `password`, `addtime`, `lastlogintime`, `logintime`,`login_num`,`status` FROM `".$tbprefix."user` WHERE `uname`='".$login_user."' AND `password`='".$login_pwd."' AND `is_valid`='1' AND 1");

		if($justice['uid']){
			if($justice['status']==1){
				
				/**
				 * 成功登录，更新登录时间与登录次数
				*/
				$dataArray['`logintime`']=$m_now_time;				 		//登录时间
				$dataArray['`lastlogintime`']=$justice['logintime'];		//最后登录时间
				$dataArray['`login_num`']=$justice['login_num']+1; 		 	//登录次数
				$dataArray['`modify_ip`']=$fun->get_web_ip(); 		 		//登录IP
				
				//1 QQ 2新浪 获取基本信息
				if($new_session_bind_set==1){
					//调用 QQ信息查询接口
					include_once (dirname(__FILE__)."/get_qq_message.php");
				}else{
					//调用sian信息查询接口
					include_once (dirname(__FILE__)."/get_sina_message.php");
				}	
				$db->update("`".$tbprefix."user`",$dataArray,$condition="uid='".$justice['uid']."' AND 1");
				
				//绑定uid
				$dataArr['uid']=$justice['uid'];
				$db->update("`".$tbprefix."user_token`",$dataArr,$condition=" `id`='{$user_token_id}' AND 1");
				
				//存储登录的基本信息
				@$_SESSION['web_user_uid']=$fun->authcode($justice['uid'],'ENCODE', $pwdconstant,$expiry=0);
				//绑定成功 销毁
				unset($_SESSION['web_sina_token_id']);	//sina同步登录保存的绑定token表id
				unset($_SESSION['web_qq_token_id']);	//QQ同步登录保存的绑定token表id
				
				//同步登陆
				
				/* shopnc login */
				
				$shoplogin = SHOPNC_DOMAIN."index.php?act=login&user_name={$login_user}&password={$login_password}&form_submit=ok";
				echo '<iframe height=0 width=0 style="display:none;" src="'.$shoplogin.'"></iframe>';
				
				/* shopnc login ok*/
				
				/* discuz login */
				
				$discuzlogin = DISCUZ_DOMAIN."member.php?mod=logging&action=login&loginsubmit=yes&handlekey=login&username={$login_user}&password={$login_password}";
				echo '<iframe height=0 width=0 style="display:none;" src="'.$discuzlogin.'"></iframe>';
				
				/* discuz login */
				$backurl = $fun->back_to_which_from($url_from);
				
				$fun->msg("登陆成功,正在前往首页...",$backurl,3,$title="登录提示",$back_color="f78a12");
				//echo "<script  type='text/javascript' language='javascript'>window.location.href='{$backurl}';</script>";
				exit();
			}else{
				$fun->msg("您的用户名出现异常,我们已经对您的用户名做出冻结处理,您无法登录",$return_page_url,3,$title="登录提示",$back_color="f78a12");
			}

		}else{
			$fun->msg("用户名或者密码错误",$return_page_url,2,$title="登录提示",$back_color="f78a12");
			$db->close();
		}

}
?>